package com.rr.learningdemo.sort;

import java.util.Objects;

/**
 * @author RR
 * @date 2021/3/13 23:22
 */
public class Bubble {
    private static void sort(int[] a) {
        if (Objects.isNull(a) || a.length < 2) {
            return;
        }
        for (int i = a.length; i >= 0; i--) {
            for (int j = 0; j < i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] a = {5, 7, 3, 4, 9, 6, 1};
        sort(a);
        for (int i:a){
            System.out.print(i + "-->");
        }
    }
}
